<?php
# 1. interface keywork usf for define interface
Interface ICanEat{
    // in interface's function doesn't need implement
    public function eat($food);

}
class human implements ICanEat {
    // after interface, must implement in class
    public function eat($food) {
        echo "Human eating ". $food . "<br>";
    }
}

class animal implements ICanEat {
    public function eat($food) {
        echo "Animanl eating " . $food . "<br>";
    }
}

$obj = new human();
$obj->eat("chicken");

$monkey = new animal();
$monkey->eat("banana");

// interface can't instantiate
#$eatOBJ = new ICanEat();

echo "<br>";

#use instanceof for verify some object either of some interface
var_dump($obj instanceof ICanEat);

function checkEat($obj) {
    if ($obj instanceof ICanEat) {
        $obj ->eat("food");
    } else {
        echo "the obj can't eat. <br>";
    }
}

//相同代码,表现不同就是多态
checkEat($obj);
checkEat($monkey);

interface ICanPee extends ICanEat {
    public function pee();
}

// can use extends for interface extend interface
class human1 implements ICanPee {
    // for child interface,parten interface function must be in child
    public function pee() {

    }

    public function eat($food) {

    }
    
}

?>
